﻿using Infrastructure.MyException;
using ShareCode.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;


/*
namespace Infrastructure.Model
{
    public interface IAllFunReturnModeAsync : IAllFunReturnMode
    {
    }
    public interface IAllFunReturnMode
    {
        bool HasErr
        {
            get;
        }

        object GetResult();
    }

    /// <summary>
    /// 如果想自定义返回值，请自定义类，并实现接口IResultDto
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class AFRM<T> : IAllFunReturnMode
    {
        public AFRM() { }
        public AFRM(T s, ShowUserLogicException err) : this(s)
        {
            MergeErr(err);
        }
        public AFRM(T s, string err):this(s)
        {
            SetMessage(err);
        }
        public AFRM(T s)
        {
            SetData(s);

        }

        public T? Data
        {
            get; set;
        }
        public ShowUserLogicException? Err
        {
            get; set;
        }

        public AFRM<T> SetData(T d)
        {
            Data = d; return this;
        }

        public AFRM<T> MergeErr(ShowUserLogicException Err)
        {
            this.Err = Err;
            return this;
        }
        public AFRM<T> Merge<TT>(AFRM<TT> aFRMAsync)
        {
            MergeErr(aFRMAsync.Err);

            return this;
        }
        public AFRM<T> SetShowType(EnumShowType type)
        {
            Err ??= new ShowUserLogicException(); Err.ShowType = (int)type; return this;
        }

        public AFRM<T> ToUnShow()
        {
            Err ??= new ShowUserLogicException();
            Err.Code = 5000;
            return this;
        }

        public AFRM<T> SetMessage(string message)
        {
            Err ??= new ShowUserLogicException();
            Err.SetMessage(message);
            return this;
        }

        public AFRM<T> AddSonMessage(string code, string msg)
        {
            Err ??= new ShowUserLogicException();
            Err.AddSonMessage(code, msg);
            return this;
        }

        public AFRM<T> AddSonMessage(Dictionary<string, string> errs)
        {
            Err ??= new ShowUserLogicException();
            Err.AddSonMessage(errs);

            return this;
        }


        public bool HasErr
        {
            get
            {
                return this.Err != null;
            }
        }

        public object GetResult()
        {
            //if (Data is IResultDto aaa)
            //{
            //    return aaa.GetResult(Err);
            //}
            //else
            //{

            var myreturn = new ResultDto<T>
            {
                Data = Data,

            };

            if (Err != default)
            {
                myreturn.Code = Err.Code;
                myreturn.Message = string.IsNullOrEmpty(Err.ErrMsg) && Err.SonErrs != default && Err.SonErrs.Count > 0 ? Err.SonErrs.First(t => true).Value[0] : Err.ErrMsg;
                myreturn.DetailMSg = Err.SonErrs;
            }

            return myreturn;
            //}
        }
   
        
    
    }


    /// <summary>
    /// AllFunReturn  工厂
    /// </summary>
    public static class AFR
    {
        #region
        public static AFRM<TT> GetObj<TT>()
        {
            return new AFRM<TT>();
        }
        public static AFRM<long> GetLongObj()
        {
            return new AFRM<long>();
        }
        public static AFRM<int> GetIntObj()
        {
            return new AFRM<int>();
        }
        public static AFRM<bool> GetBoolObj()
        {
            return new AFRM<bool>();
        }
        public static AFRM<string> GetStrObj()
        {
            return new AFRM<string>();
        }


        public static AFRM<TT> GetObj<TT>(TT par)
        {
            return new AFRM<TT>() { Data = par };
        }
        public static AFRM<long> GetLongObj(long par)
        {
            return new AFRM<long>() { Data = par };
        }
        public static AFRM<int> GetIntObj(int par)
        {
            return new AFRM<int>() { Data = par };
        }
        public static AFRM<bool> GetBoolObj(bool par)
        {
            return new AFRM<bool>() { Data = par };
        }
        public static AFRM<string> GetStrObj(string par)
        {
            return new AFRM<string>() { Data = par };
        }


        public static AFRM<TT> GetObj<TT, TT2>(AFRM<TT2> obj2)
        {
            var obj = new AFRM<TT>();

            return obj.MergeErr(obj2.Err);
        }
        public static AFRM<TT> GetObj<TT, TT2>(TT par, AFRM<TT2> obj2)
        {
            var obj = GetObj(par);

            return obj.MergeErr(obj2.Err);
        }
        public static AFRM<TT> GetObj<TT, TT2>(AFRM<TT> obj, AFRM<TT2> obj2)
        {
            obj ??= new AFRM<TT>();

            return obj.MergeErr(obj2.Err);
        }

        public static AFRM<TT> GetObj<TT>(AFRM<TT> obj, TT par)
        {
            obj ??= new AFRM<TT>(); obj.Data = par; return obj;
        }

        public static AFRM<TT> ToUnShow<TT>()
        {
            var obj = new AFRM<TT>(); obj.ToUnShow(); return obj;
        }
        public static AFRM<TT> ToUnShow<TT>(AFRM<TT> obj)
        {
            obj ??= new AFRM<TT>(); obj.ToUnShow(); return obj;
        }

        #endregion

    }


    public enum EnumShowType
    {
        silent = 0,
        message = 1,
        warn = 2,
        error = 4,
        notification = 9

    }


}
*/